﻿using System;
using System.Linq;
using DAL;
using Entity;
using Utils;
using Library;
using DataContext;
using System.Collections.Generic;

namespace HighLowGameBLL
{
    public class CtrHiLoGame
    {
        public int UpdateGame(int id, string name, int? minimumValue, int? maximumValue, double? minimumBet, double? maximumBet,
            double? rate, double? randomRate,
            int? startExtraLife, int? startOutOf, int? startNudges, int? startFreeSpin,
            int? extraLife, int? outOf, int? nudges, int? freeSpin,
            int? maximumExtraLife, int? maximumOutOf, int? maximumNudges, int? maximumFreeSpin,
            double? jackpotMinBetAu, double? jackpotStartAu,
            double? jackpotAu, double? jackpotBlockAu, double? jackpotjumpAu, int? jackpotStatusAu,
            double? jackpotMinBetAg, double? jackpotStartAg,
            double? jackpotAg, double? jackpotBlockAg, double? jackpotjumpAg, int? jackpotStatusAg,
            double? maximumJackpotAu, double? maximumJackpotAg)
        {
            HighLowGameDataContext dataContext = DB.HighLowGameInstance;
            var result = dataContext.uspHiLoGameSelect(id).First();
            if (string.IsNullOrEmpty(name))
                name = result.Name;
            minimumValue = result.MinimumValue;
            maximumValue = result.MaximumValue;
            if (minimumBet == null)
                minimumBet = result.MinimumBet;
            if (maximumBet == null)
                maximumBet = result.MaximumBet;
            if (rate == null)
                rate = result.Rate;
            if (randomRate == null)
                randomRate = result.RandomRate;
            if (startExtraLife == null)
                startExtraLife = result.StartExtraLife;
            if (startOutOf == null)
                startOutOf = result.StartOutOf;
            if (startNudges == null)
                startNudges = result.StartNudges;
            if (freeSpin == null)
                freeSpin = result.FreeSpin;
            if (extraLife == null)
                extraLife = result.ExtraLife;
            if (outOf == null)
                outOf = result.OutOf;
            if (nudges == null)
                nudges = result.Nudges;
            if (freeSpin == null)
                freeSpin = result.FreeSpin;
            if (maximumExtraLife == null)
                maximumExtraLife = result.MaximumExtraLife;
            if (maximumOutOf == null)
                maximumOutOf = result.MaximumOutOf;
            if (maximumNudges == null)
                maximumNudges = result.MaximumNudges;
            if (maximumFreeSpin == null)
                maximumFreeSpin = result.MaximumFreeSpin;

            if (jackpotMinBetAu == null)
                jackpotMinBetAu = result.JackpotMinBetAu;
            if (jackpotStartAu == null)
                jackpotStartAu = result.JackpotStartAu;
            if (jackpotAu == null)
                jackpotAu = result.JackpotAu;
            if (jackpotBlockAu == null)
                jackpotBlockAu = result.JackpotBlockAu;
            if (jackpotjumpAu == null)
                jackpotjumpAu = result.JackpotJumpAu;
            if (jackpotStatusAu == null)
                jackpotStatusAu = result.JackpotStatusAu;

            if (jackpotMinBetAg == null)
                jackpotMinBetAg = result.JackpotMinBetAg;
            if (jackpotStartAg == null)
                jackpotStartAg = result.JackpotStartAg;
            if (jackpotAg == null)
                jackpotAg = result.JackpotAg;
            if (jackpotBlockAg == null)
                jackpotBlockAg = result.JackpotBlockAg;
            if (jackpotjumpAg == null)
                jackpotjumpAg = result.JackpotJumpAg;
            if (jackpotStatusAg == null)
                jackpotStatusAg = result.JackpotStatusAg;
            if (maximumJackpotAu == null)
                maximumJackpotAu = result.MaximumJackpotAu;
            if (maximumJackpotAg == null)
                maximumJackpotAg = result.MaximumJackpotAg;

            return DB.HighLowGameInstance.uspHiLoGameUpdate(id, name, minimumValue, maximumValue, minimumBet, maximumBet,
                rate, randomRate, startExtraLife, startOutOf, startNudges, startFreeSpin,
                extraLife, outOf, nudges, freeSpin, maximumExtraLife, maximumOutOf, maximumNudges, maximumFreeSpin,
                jackpotMinBetAu, jackpotStartAu,
                jackpotAu, jackpotBlockAu, jackpotjumpAu, jackpotStatusAu,
                jackpotMinBetAg, jackpotStartAg,
                jackpotAg, jackpotBlockAg, jackpotjumpAg, jackpotStatusAg,
                maximumJackpotAu, maximumJackpotAg);
        }

        public int UpdateJackpotAu(int gameId, double jackpotMinBetAu, double? jackpotStartAu, double? jackpotAu, double? jackpotBlockAu, double? jackpotJumpAu, int? jackpotStatusAu, double? maximumJackpotAu)
        {
            return UpdateGame(gameId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                jackpotMinBetAu, jackpotStartAu,
                jackpotAu, jackpotBlockAu, jackpotJumpAu, jackpotStatusAu,
                null, null, null, null, null, null, maximumJackpotAu, null);
        }

        public int UpdateJackpotAg(int gameId, double jackpotMinBetAg, double? jackpotStartAg, double? jackpotAg, double? jackpotBlockAg, double? jackpotJumpAg, int? jackpotStatusAg, double? maximumJackpotAg)
        {
            return UpdateGame(gameId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                null, null, null, null, null, null,
                jackpotMinBetAg, jackpotStartAg,
                jackpotAg, jackpotBlockAg, jackpotJumpAg, jackpotStatusAg, null, maximumJackpotAg);
        }

        public uspHiLoGameSelectResult SelectGame(int id)
        {
            return DB.HighLowGameInstance.uspHiLoGameSelect(id).FirstOrDefault();
        }

        public List<uspHiLoGameSelelctAllResult> SelectAllGame()
        {
            return DB.HighLowGameInstance.uspHiLoGameSelelctAll().ToList();
        }
    }
}
